#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.



import sys
import argparse

from fce_util import deploy, clean
from fce_util import raymgr
from fce_util import cmdexec


#log.init('/usr/local/fce/logs/fceutil.log')

__header__ = """
F  O  C  T
C  P  O  O
E  E  N  O
   R  T  L
   A  R  S
   T  O
   O  L
   R
"""

def get_parser():
    parser = argparse.ArgumentParser(
        prog = 'fceutil',
        formatter_class = argparse.RawDescriptionHelpFormatter,
        description = 'Easy fce operator control tools\n\n%s' % __header__,
        )

    sub = parser.add_subparsers(
        title = 'commands',
        metavar = 'COMMAND',
        help = 'description',
        dest = 'cmd'
        )

    sub.required = True

    entry_points = [
        ('rayc', raymgr.make),
        ('deploy', deploy.make),
        ('clean', clean.make),
        ('cmdexec', cmdexec.make),

    ]

    for (name, fn) in entry_points:
        p = sub.add_parser(
            name,
            description = fn.__doc__,
            help = fn.__doc__,
            )
        fn(p)
        p.required = True

    return parser

def _main(args = None, namespace = None):

    parser = get_parser()
    if len(sys.argv) < 2:
        parser.print_help()
        sys.exit(-1)
    else:
        args, _ = parser.parse_known_args(args = args, namespace = namespace)

    res = args.func(args)

    return res

def main(args = None, namespace = None):
       _main(args = args, namespace = namespace)
